<?php
$v_move_record_to_leader = sizeof($arr_single_recordtype);
if($v_move_record_to_leader > 0) {
	$v_move_record_to_leader_cheched = $arr_single_recordtype['C_MOVE_TO_LEADER'];
}
//echo 'gggggggggggggg' . $v_move_record_to_leader_cheched.'<br>';
//exit;
set_time_limit(_CONST_REPORT_TIMEOUT);
$v_current_style_name = "round_row";
$v_current_date = "ng&#224;y ". date("d"). " th&#225;ng " . date("m")." n&#259;m " . date("Y");
$v_report_date = $_ISA_OWNER_REPORT_NAME;
$v_export_type = 1;
if(isset($_REQUEST['rad_exporttype'])){
	$v_export_type = $_REQUEST['rad_exporttype'];
}

$v_reporttype_filter = "";
if(isset($_REQUEST['hdn_reporttype_filter'])){
	$v_reporttype_filter = $_REQUEST['hdn_reporttype_filter'];
} 

//echo $v_reporttype_filter;
//Begin//Xay dung chuoi XML chua gia tri
$v_list_xml_tag = "";
if(isset($_REQUEST['hdn_list_xml_tag'])){
	$v_list_xml_tag = $_REQUEST['hdn_list_xml_tag'];
}
$v_list_xml_value = "";
if(isset($_REQUEST['hdn_list_xml_value'])){
	$v_list_xml_value = $_REQUEST['hdn_list_xml_value'];
}
$v_xml_str = '<?xml version="1.0" encoding="UTF-8"?><root><data_list>';
for ($i=0; $i<_list_get_len($v_list_xml_tag,_CONST_SUB_LIST_DELIMITOR); $i++){
	$v_xml_str = $v_xml_str ."<"._list_get_at($v_list_xml_tag,$i,_CONST_SUB_LIST_DELIMITOR).">";
	$v_xml_str = $v_xml_str .trim(_replace_XML_bad_char(_list_get_at($v_list_xml_value,$i,_CONST_SUB_LIST_DELIMITOR)));
	$v_xml_str = $v_xml_str ."</"._list_get_at($v_list_xml_tag,$i,_CONST_SUB_LIST_DELIMITOR).">";
}
$v_xml_str = $v_xml_str . "</data_list></root>";

//echo htmlspecialchars($v_xml_str)."<br>";
//Doc file chua cau truc cua bao cao

$v_report_xml_file = Get_text_from_array($arr_all_reporttype,'6','6','5', $v_reporttype_filter);
//echo $v_report_xml_file.'<br/>';
$v_report_xml_file = "../xml/report/".$v_report_xml_file;
if (!is_file($v_report_xml_file)){
	$v_report_xml_file = "../xml/report/bao_cao_chung.xml";
}

// Danh sach cac file bao cao cua VPDKQSDD
$v_array_report_xml_file_landroom =  array( "../xml/report/008_bao_cao_tien_do_giai_quyet_ho_so_vpdkqsdd.xml",
											"../xml/report/010_bao_cao_tien_do_giai_quyet_ho_so_vpdkqsdd.xml",
											"../xml/report/025_bao_cao_tien_do_giai_quyet_ho_so_vpdkqsdd.xml",
											"../xml/report/026_bao_cao_tien_do_giai_quyet_ho_so_vpdkqsdd.xml",
											"../xml/report/027_bao_cao_tien_do_giai_quyet_ho_so_vpdkqsdd.xml",
											"../xml/report/028_bao_cao_tien_do_giai_quyet_ho_so_vpdkqsdd.xml",
											"../xml/report/029_bao_cao_tien_do_giai_quyet_ho_so_vpdkqsdd.xml",
											"../xml/report/030_bao_cao_tien_do_giai_quyet_ho_so_vpdkqsdd.xml",
											"../xml/report/031_bao_cao_tien_do_giai_quyet_ho_so_vpdkqsdd.xml",
											"../xml/report/032_bao_cao_tien_do_giai_quyet_ho_so_vpdkqsdd.xml",
											"../xml/report/033_bao_cao_tien_do_giai_quyet_ho_so_vpdkqsdd.xml",
											"../xml/report/034_bao_cao_tien_do_giai_quyet_ho_so_vpdkqsdd.xml",
											"../xml/report/035_bao_cao_tien_do_giai_quyet_ho_so_vpdkqsdd.xml",
											"../xml/report/036_bao_cao_tien_do_giai_quyet_ho_so_vpdkqsdd.xml",
											"../xml/report/037_bao_cao_tien_do_giai_quyet_ho_so_vpdkqsdd.xml",
											"../xml/report/038_bao_cao_tien_do_giai_quyet_ho_so_vpdkqsdd.xml",
											"../xml/report/039_bao_cao_tien_do_giai_quyet_ho_so_vpdkqsdd.xml",
											"../xml/report/040_bao_cao_tien_do_giai_quyet_ho_so_vpdkqsdd.xml",
											"../xml/report/041_bao_cao_tien_do_giai_quyet_ho_so_vpdkqsdd.xml",
											"../xml/report/042_bao_cao_tien_do_giai_quyet_ho_so_vpdkqsdd.xml",
											"../xml/report/043_bao_cao_tien_do_giai_quyet_ho_so_vpdkqsdd.xml",
											"../xml/report/044_bao_cao_tien_do_giai_quyet_ho_so_vpdkqsdd.xml",
											"../xml/report/001_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/002_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/003_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",											
											"../xml/report/004_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/005_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/006_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/007_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/008_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/009_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/010_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/011_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/012_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/013_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/014_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/015_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/016_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/017_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/018_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/019_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/020_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/021_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/022_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/023_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/024_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/025_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/026_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/027_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/028_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/029_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/030_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/031_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/032_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/033_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/034_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",		
											"../xml/report/035_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/036_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/037_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/038_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/039_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/040_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/041_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/042_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/043_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/044_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/045_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/046_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/047_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml",
											"../xml/report/048_bao_cao_tien_do_giai_quyet_ho_so_theo_hinh.xml");										
$arr_xml_file_general_report = array (
										"../xml/report/bao_cao_tong_hop_tinh_hinh_can_bo_thu_ly_trinh_ky_ho_so.xml",
										"../xml/report/048_bao_cao_tong_hop.xml"
									  );		
									  
if(in_array($v_report_xml_file,$v_array_report_xml_file_landroom)!=true){
	$v_report_xml_string = _read_file($v_report_xml_file);
	//echo htmlspecialchars($v_report_xml_string); exit;
	//lay du lieu cua bao cao
	$table_struct_rax = new RAX(); 
	$table_struct_rec = new RAX(); 
	$table_struct_rax->open($v_report_xml_string);
	$table_struct_rax->record_delim = 'report_sql';
	$table_struct_rax->parse();
	$table_struct_rec = $table_struct_rax->readRecord(); 
	$table_struct_row = $table_struct_rec->getRow();
	$v_sql_string = _restore_XML_bad_char($table_struct_row["sql"]);
	
	//DATCQ: Loc Dia_Phuong_Kinh_Doanh va Nhom_Nganh_Nghe Cac Bao Cao 001,048 ... 260908 ...
	//Mo ta: neu cac gia tri loc co gia tri thi se thay the #...# thanh chuoi loc, con khong thi thay bang khoang trang
	$array_loai_bo_gia_tri_loc = array("../xml/report/001_danh_sach_cac_ho_dang_ky_kinh_doanh_trong_thang_nam.xml",
										"../xml/report/001_danh_sach_cac_ho_cap_moi_dang_ky_kinh_doanh_trong_thang_nam.xml",
										"../xml/report/048_danh_sach_cac_ho_thay_doi_dang_ky_kinh_doanh_trong_thang_nam.xml",
										"../xml/report/048_danh_sach_cac_ho_cap_lai_dang_ky_kinh_doanh_trong_thang_nam.xml",
										"../xml/report/048_danh_sach_cac_ho_cham_dut_kinh_doanh_trong_thang_nam.xml",
										"../xml/report/009_danh_sach_cap_phep_xay_dung_theo_hinh_thuc_ghi_chu.xml",
										"../xml/report/048_bao_cao_tong_hop.xml");
	if(in_array($v_report_xml_file,$array_loai_bo_gia_tri_loc))
		$v_sql_string = replace_tag_xml_value_in_sql_datcq_260908($v_sql_string,$v_report_xml_string,$v_xml_str); 
	//End: Loc Dia_Phuong_Kinh_Doanh va Nhom_Nganh_Nghe Cac Bao Cao 001,048 ... 260908 ...
	//echo $v_sql_string; //exit;
    if($v_report_xml_file=="../xml/report/008_danh_sach_ho_so_tiep_nhan.xml"){
		$array = _get_list_user($_SESSION['arr_all_staff']);
		//	var_dump($array); exit();
		//	================ Bang Danh Sach Nhan Vien =================================	
		$sql = " Create Table TEMP_USER(P_ID int IDENTITY (1,1),PK_HANDLER int, C_NAME_USER nvarchar(1000))";
		for($i = 0; $i < count($array); $i++){
			$sql .= "Insert into TEMP_USER(PK_HANDLER,C_NAME_USER) values ('".$array[$i][0]."',N'".$array[$i][1]."')";
		}
		if(_is_sqlserver()){
			$ado_conn->SetFetchMode(ADODB_FETCH_ASSOC);
			$ado_conn->_Execute($sql); 
		}
	}
	
	$v_sql_string = replace_tag_xml_value_in_sql($v_sql_string,$v_report_xml_string,$v_xml_str);
//	echo $v_sql_string.'<br>';	
	
	$v_group_by = $table_struct_row["group_by"];
	$v_group_name = $table_struct_row["group_name"];
	$v_xml_data_compare = $table_struct_row["xml_data"];
	$v_calculate_total = $table_struct_row["calculate_total"];
	$v_calculate_group = $table_struct_row["calculate_by_group"];
	//Lay du lieu cua bao cao tu database
	$arr_all_record = Query_Data_For_Colunm_name($v_sql_string);	
	//var_dump($arr_all_record);
	/*mobified by tuyenntt*/
if($v_report_xml_file == "../xml/report/all_phu_luc_bao_cao_tong_hop_br.xml")
	{
		$arr_all_record[sizeof($arr_all_record)]['DON_VI']= 'Tổng cộng';
		for ($i = 0 ; $i < sizeof ($arr_all_record) ; $i ++)
		{
			if($arr_all_record[$i]['tong_giai_quyet'] > 0 )
			{
				$arr_all_record[$i]['tile_qqdunghen'] = round( $arr_all_record[$i]['gq_dung_hen'] /$arr_all_record[$i]['tong_giai_quyet'] *100 ).'%';
				$arr_all_record[$i]['tile_qqtrehen'] = (100 - round( $arr_all_record[$i]['gq_dung_hen'] /$arr_all_record[$i]['tong_giai_quyet'] *100 )). '%';//round($arr_all_record[$i]['GQ_Tre_Hen'] /$arr_all_record[$i]['tong_giai_quyet'] *100 ).'%';					
			}
			else
			{
				$arr_all_record[$i]['tile_qqdunghen'] = '0%' ;
				$arr_all_record[$i]['tile_qqtrehen'] = '0%' ;
			}
			
			if($arr_all_record[$i]['tong_chua_giai_quyet'] > 0 )
			{
				$arr_all_record[$i]['tile_chuadn'] = round($arr_all_record[$i]['Chua_DH'] /$arr_all_record[$i]['tong_chua_giai_quyet'] *100 ).'%';
				$arr_all_record[$i]['tile_trehen'] = (100 -round($arr_all_record[$i]['Chua_DH'] /$arr_all_record[$i]['tong_chua_giai_quyet'] *100 )).'%'; //round($arr_all_record[$i]['tre_hen'] /$arr_all_record[$i]['tong_chua_giai_quyet'] *100 ).'%';
			}
			else
			{
				$arr_all_record[$i]['tile_chuadn'] = '0%' ;
				$arr_all_record[$i]['tile_trehen'] = '0%';
			}
		}
		
		$arr_all_record[ sizeof ($arr_all_record) - 1]['tong_tiep_nhan'] = 0;
		$arr_all_record[ sizeof ($arr_all_record) - 1]['tong_giai_quyet'] = 0;
		$arr_all_record[ sizeof ($arr_all_record) - 1]['gq_dung_hen'] = 0;
		$arr_all_record[ sizeof ($arr_all_record) - 1]['tile_qqdunghen'] = 0;
		$arr_all_record[ sizeof ($arr_all_record) - 1]['GQ_Tre_Hen'] = 0;
		$arr_all_record[ sizeof ($arr_all_record) - 1]['tile_qqtrehen'] = 0;
		$arr_all_record[ sizeof ($arr_all_record) - 1]['tong_chua_giai_quyet'] = 0;
		$arr_all_record[ sizeof ($arr_all_record) - 1]['tre_hen'] = 0;
		$arr_all_record[ sizeof ($arr_all_record) - 1]['tile_trehen'] = 0;
		$arr_all_record[ sizeof ($arr_all_record) - 1]['Chua_DH'] = 0;
		$arr_all_record[ sizeof ($arr_all_record) - 1]['tile_chuadn']  = 0;

		for($i=0; $i < sizeof ($arr_all_record) - 1 ; $i ++)
		{
			$arr_all_record[ sizeof ($arr_all_record) - 1]['tong_tiep_nhan'] = $arr_all_record[ sizeof ($arr_all_record) - 1]['tong_tiep_nhan'] + $arr_all_record[$i]['tong_tiep_nhan'] ;

			$arr_all_record[ sizeof ($arr_all_record) - 1]['tong_giai_quyet'] = $arr_all_record[ sizeof ($arr_all_record) - 1]['tong_giai_quyet'] + $arr_all_record[$i]['tong_giai_quyet'] ;

			$arr_all_record[ sizeof ($arr_all_record) - 1]['gq_dung_hen'] = $arr_all_record[ sizeof ($arr_all_record) - 1]['gq_dung_hen'] + $arr_all_record[$i]['gq_dung_hen'] ;

			

			$arr_all_record[ sizeof ($arr_all_record) - 1]['GQ_Tre_Hen'] = $arr_all_record[ sizeof ($arr_all_record) - 1]['GQ_Tre_Hen'] + $arr_all_record[$i]['GQ_Tre_Hen'] ;

			

			$arr_all_record[ sizeof ($arr_all_record) - 1]['tong_chua_giai_quyet'] = $arr_all_record[ sizeof ($arr_all_record) - 1]['tong_chua_giai_quyet'] + $arr_all_record[$i]['tong_chua_giai_quyet'] ;

			$arr_all_record[ sizeof ($arr_all_record) - 1]['tre_hen'] = $arr_all_record[ sizeof ($arr_all_record) - 1]['tre_hen'] + $arr_all_record[$i]['tre_hen'] ;

			

			$arr_all_record[ sizeof ($arr_all_record) - 1]['Chua_DH'] = $arr_all_record[ sizeof ($arr_all_record) - 1]['Chua_DH'] + $arr_all_record[$i]['Chua_DH'] ;

			
	    }
		if($arr_all_record[ sizeof ($arr_all_record) - 1]['tong_giai_quyet'] > 0 )
		{
		 $arr_all_record[ sizeof ($arr_all_record) - 1]['tile_qqdunghen'] = round($arr_all_record[ sizeof ($arr_all_record) - 1]['gq_dung_hen']/ $arr_all_record[ sizeof ($arr_all_record) - 1]['tong_giai_quyet'] * 100).'%';
		 $arr_all_record[ sizeof ($arr_all_record) - 1]['tile_qqtrehen'] =(100 - round($arr_all_record[ sizeof ($arr_all_record) - 1]['gq_dung_hen']/ $arr_all_record[ sizeof ($arr_all_record) - 1]['tong_giai_quyet'] * 100)). '%';//round( $arr_all_record[ sizeof ($arr_all_record) - 1]['GQ_Tre_Hen']/ $arr_all_record[ sizeof ($arr_all_record) - 1]['tong_giai_quyet'] * 100). '%';
		}
		if($arr_all_record[ sizeof ($arr_all_record) - 1]['tong_chua_giai_quyet'] >0)
		{
		 $arr_all_record[ sizeof ($arr_all_record) - 1]['tile_trehen'] =round( $arr_all_record[ sizeof ($arr_all_record) - 1]['tre_hen']/ $arr_all_record[ sizeof ($arr_all_record) - 1]['tong_chua_giai_quyet'] *100 ). '%';
		 $arr_all_record[ sizeof ($arr_all_record) - 1]['tile_chuadn'] = (100 - round( $arr_all_record[ sizeof ($arr_all_record) - 1]['tre_hen']/ $arr_all_record[ sizeof ($arr_all_record) - 1]['tong_chua_giai_quyet'] *100 )). '%';//round($arr_all_record[ sizeof ($arr_all_record) - 1]['Chua_DH'] / $arr_all_record[ sizeof ($arr_all_record) - 1]['tong_chua_giai_quyet'] *100 ).'%';
		}

	}

	/*the end modified by tuyenntt*/
/*********************************************************************/
//Tong von kinh doanh _NgocNTM
//print_r($arr_all_record);
$array_tong_von_kinh_doanh = array('../xml/report/001_danh_sach_cac_ho_dang_ky_kinh_doanh_trong_thang_nam.xml',
									'../xml/report/001_danh_sach_cac_ho_cap_moi_dang_ky_kinh_doanh_trong_thang_nam.xml',
									'../xml/report/048_danh_sach_cac_ho_thay_doi_dang_ky_kinh_doanh_trong_thang_nam.xml',
									'../xml/report/048_danh_sach_cac_ho_cap_lai_dang_ky_kinh_doanh_trong_thang_nam.xml',
									'../xml/report/048_danh_sach_cac_ho_cham_dut_kinh_doanh_trong_thang_nam.xml',
									'../xml/report/048_bao_cao_tong_hop.xml'
);
if($v_reporttype_filter == '001'||in_array($v_report_xml_file,$array_tong_von_kinh_doanh)==1){
	$tong=0;
	for($i=0;$i<sizeof($arr_all_record);$i++){ 
		$arr_all_record[$i]['von_kinh_doanh'] = str_replace(",","",$arr_all_record[$i]['von_kinh_doanh']);
		$tong=$tong+($arr_all_record[$i]['von_kinh_doanh']);
	}
}

//DatCQ Tinh tong cac cot dien tich xay dung, dien tich san bao cao 009_danh_sach_cap_phep_xay_dung_theo_hinh_thuc_ghi_chu.xml
if($v_reporttype_filter == '009'||$v_report_xml_file=='../xml/report/009_danh_sach_cap_phep_xay_dung_theo_hinh_thuc_ghi_chu.xml')
{
	$tong_dtxd=0;
	$tong_dts=0;
	
	for($i=0;$i<sizeof($arr_all_record);$i++){ 
		$arr_all_record[$i]['building_floor1_area'] = (float)$arr_all_record[$i]['building_floor1_area'];
		$tong_dtxd=$tong_dtxd+$arr_all_record[$i]['building_floor1_area'];
	}
	
	for($i=0;$i<sizeof($arr_all_record);$i++){ 
		$arr_all_record[$i]['building_area_total'] = (float)$arr_all_record[$i]['building_area_total'];
		$tong_dts=$tong_dts+$arr_all_record[$i]['building_area_total'];
	}
}
//print_r($arr_all_record);
if($v_report_xml_file=='../xml/report/bao_cao_tong_hop_tinh_hinh_can_bo_thu_ly_trinh_ky_ho_so.xml'){
  for($i=0;$i<sizeof($arr_all_record);$i++){ 
    //if ($arr_all_record[$i]['fk_handler'] != null or $arr_all_record[$i]['fk_handler'] != 0)
	   		$arr_all_record[$i]['FK_HANDLER'] =get_text_staff_by_id(intval($arr_all_record[$i]['FK_HANDLER']));	
	}
}

//End DatCQ Tinh tong cac cot dien tich xay dung, dien tich san bao cao 009_danh_sach_cap_phep_xay_dung_theo_hinh_thuc_ghi_chu.xml

//DatCQ: Bao cao tong hop 048 08102008
if(in_array($v_report_xml_file,$array_tong_von_kinh_doanh)){
	$DKCL = 0;	$DKTD = 0;	$NKD = 0;
	for($i=0;$i<sizeof($arr_all_record);$i++){
		if($arr_all_record[$i]['RECORD_FORM']=="DKCL")
			$DKCL = $DKCL +1;
		if($arr_all_record[$i]['RECORD_FORM']=="DKTD")
			$DKTD = $DKTD +1;
		if($arr_all_record[$i]['RECORD_FORM']=="NKD")
			$NKD = $NKD +1;
	}
}
//print_r($arr_all_record);
//echo $DKCL.'|'.$DKTD.'|'.$NKD;
//End: Bao cao tong hop 048 08102008

$v_count = sizeof($arr_all_record);
	//lay cac thong tin tieu de cua form
	$table_struct_rax = new RAX(); 
	$table_struct_rec = new RAX(); 
	$table_struct_rax->open($v_report_xml_string);
	$table_struct_rax->record_delim = 'table_struct_of_filter_form';
	$table_struct_rax->parse();
	$table_struct_rec = $table_struct_rax->readRecord(); 
	$table_struct_row = $table_struct_rec->getRow();
	$v_form_title = $table_struct_row["form_title"];
	
	// Lay ten file HTML mo ta phan tieu de cac cot
	$v_report_label_file = trim($table_struct_row["table_header_file"]);
	$v_first_col_width = $table_struct_row["first_col_width"];
	$v_second_col_width = (100-$v_first_col_width)."%";
	//Xau chua toan bo bao cao
	$v_html_string = '';
	
	//Phan than cua bao cao
	//cac tieu de cot
	$v_html_body = '';
	$v_html_temp_width = '';
	$v_html_temp_label = '';
	$v_column = 0;
	
	$v_html_string = '';
	$table_struct_rax = new RAX(); 
	$table_struct_rec = new RAX(); 
	$table_struct_rax->open($v_report_xml_string);
	$table_struct_rax->record_delim = 'col';
	$table_struct_rax->parse();
	$table_struct_rec = $table_struct_rax->readRecord(); 
	while ($table_struct_rec) { 
		$table_struct_row = $table_struct_rec->getRow();
		$v_type =  $table_struct_row["type"]; 
		$v_label = $table_struct_row["label"];
		$v_width = $table_struct_row["width"];
		$v_align = $table_struct_row["align"];
		//Lay danh sach do rong cac cot cua bang
		$v_html_temp_width = $v_html_temp_width  . '<col width="'.$v_width .'">';
		//Lay danh sach cac tieu de cua cot
		$v_html_temp_label = $v_html_temp_label . '<td class="header" align="'.$v_align.'">'.$v_label.'</td>';
		$arr_type[$v_column] = $v_type;
		$arr_align[$v_column] = $v_align;
		$table_struct_rec = $table_struct_rax->readRecord();
		$v_column ++;
	}
	//echo 'v_column'.$v_column; exit;
	$v_width_col = 100/$v_column;
	$v_html_col_list = $v_html_col_list .str_repeat("<col width:'$v_width_col%'>",$v_column);
	//Neu ton tai file dinh dang tieu de cac cot
	if ( (!is_null($v_report_label_file)) && ($v_report_label_file != "")){
		//Tieu de cot doc tu file HTML vao
		$v_report_label_file = _CONST_REPORT_LABEL_FILE_URL_PATH.$v_report_label_file;	
		$v_html_label_content = _read_file($v_report_label_file);	
		$v_html_body = $v_html_body.$v_html_label_content;
	}else{
		$v_html_body = $v_html_body  . '<table class="report_table" style="width:99%" border="0" cellpadding="0" cellspacing="0">';
		$v_html_body = $v_html_body  . $v_html_temp_width;
		$v_html_body = $v_html_body  . '<tr>';
		$v_html_body = $v_html_body  . $v_html_temp_label;
		$v_html_body = $v_html_body  . '</tr>';
	}
	//Khoi tao thu tu cua danh sach va nhom 
	$group_index=1;
	$v_inc = 1;
	if ($v_count >0){
		//Vong lap hien thi danh sach cac ho so
		$v_old_row = $arr_all_record[0];
		for ($i=0; $i< $v_column; $i++){
			$arr_calculate[$i] = 0;
		}
		for($row_index = 0;$row_index <$v_count ;$row_index++){
			$v_url = "";
			$v_recordset = $arr_all_record[$row_index];
			$v_received_record_xml_data = $arr_all_record[$row_index]['C_RECEIVED_RECORD_XML_DATA'];
			$v_recordtype_code = $arr_all_record[$row_index]['FK_RECORDTYPE'];
			$v_group_name_label = $arr_all_record[$row_index][$v_group_name];
			if ($v_current_style_name == "odd_row"){
				$v_current_style_name = "round_row";
			}else{
				$v_current_style_name = "odd_row";
			}
			//Bat dau 1 dong			
			$table_struct_rax = new RAX(); 
			$table_struct_rec = new RAX(); 
			$table_struct_rax->open($v_report_xml_string);
			$table_struct_rax->record_delim = 'col';
			$table_struct_rax->parse();
			$table_struct_rec = $table_struct_rax->readRecord();
			$v_col_index = 0; 
			$v_html_body_row = '';
			//In tieu de cua nhom // row dau tien 
			if (trim($v_group_by)!="" && $row_index == 0){	
			//var_dump ($arr_all_record);
				if (in_array($v_report_xml_file,$arr_xml_file_general_report)){
					$v_html_group = $v_html_body  .'<tr class="'.$v_current_style_name.'" >';
					$v_html_group = $v_html_group  .'<td class="data"><B>'.$group_index.'</B></td>';
					$v_html_group = $v_html_group  .'<td class="data" colspan = 2	 ><B>'.$arr_all_record[$row_index][$v_group_by].'</B></td>';
					$v_html_body = '';					
				}
				else if(in_array($v_report_xml_file,$array_tong_von_kinh_doanh))
				{
					
				$v_html_body = $v_html_body  .'<tr class="'.$v_current_style_name.'" >';
				$v_html_body = $v_html_body  .'<td class="data"><B>'.$group_index.'</B></td>';
				$v_name=$arr_all_record[$row_index+1][$v_group_by];
				if($arr_all_record[$row_index][$v_group_by]=="DKCL")
				{$v_name='&#272;&#259;ng k&yacute; c&#7845;p l&#7841;i';			
				$v_html_body = $v_html_body  .'<td class="data" colspan="'.($v_column-1).'"><B>'.$v_name." : ".$DKCL.'</B></td>';}
				}
				else{
				$v_html_body = $v_html_body  .'<tr class="'.$v_current_style_name.'" >';
				$v_html_body = $v_html_body  .'<td class="data"><B>'.$group_index.'</B></td>';
				$v_html_body = $v_html_body  .'<td class="data" colspan="'.($v_column-1).'"><B>'.$arr_all_record[$row_index][$v_group_by].'</B></td>';}
				$v_html_body = $v_html_body  .'</tr>';
			}
		while ($table_struct_rec) { 
				$table_struct_row = $table_struct_rec->getRow();
				$v_type = $table_struct_row["type"];
				$v_width = $table_struct_row["width"];
				$v_align = $table_struct_row["align"];
				$v_xml_data = $table_struct_row["xml_data"];
				$v_calculate = $table_struct_row["calculate"];
				$v_compare_value = $table_struct_row["compare_value"];
				$v_column_name = $table_struct_row["column_name"];
					
				//Lay the xml chua noi dung can hien thi tu danh sach tuong ung voi ma
				$v_xml_tag_in_db = get_value_from_two_list($v_recordtype_code,$table_struct_row["recordtype_code_list"],$table_struct_row["xml_tag_in_db_list"]);
				$v_selectbox_option_sql = $table_struct_row["selectbox_option_sql"];
				$v_php_function = $table_struct_row["php_function"];
				$arr_xml_tag_in_db = explode(".",$v_xml_tag_in_db);
				if (sizeof($arr_xml_tag_in_db)>1){
					$v_received_record_xml_data = $arr_all_record[$row_index][$arr_xml_tag_in_db[0]];
					$v_xml_tag_in_db = $arr_xml_tag_in_db[1];
				}				
				if ($v_xml_data=="true" && $v_received_record_xml_data!="" && !is_null($v_received_record_xml_data)){
					$column_rax = new RAX(); 
					$column_rec = new RAX();
					$column_rax->open($v_received_record_xml_data);
					$column_rax->record_delim = 'data_list';
					$column_rax->parse();
					$column_rec = $column_rax->readRecord(); 
					$column_row = $column_rec->getRow();
					if ($v_xml_tag_in_db =="" && is_null($v_xml_tag_in_db)){
						$v_xml_tag_in_db = $table_struct_row["xml_tag_in_db"];
					}
					//echo $v_xml_tag_in_db."sssssss<br>";
					$v_value = _restore_XML_bad_char($column_row[$v_xml_tag_in_db]);
					
				}else{
					//var_dump ($arr_all_record);
					$v_value = $arr_all_record[$row_index][$v_column_name];

					//DatCQ: Kiem tra xem co thay doi giay phep lan khac ko, neu ko co NgayDK = ngay_ban_hanh_2
					if($v_value==''&&$v_column_name=='ngay_ban_hanh'&&($v_report_xml_file == '../xml/report/001_danh_sach_cac_ho_dang_ky_kinh_doanh_trong_thang_nam.xml'||$v_report_xml_file == '../xml/report/048_danh_sach_cac_ho_cham_dut_kinh_doanh_trong_thang_nam.xml'))
						$v_value = $arr_all_record[$row_index]['ngay_ban_hanh_2'];
					//DatCQ: End
					//DatCQ 13/08/2008: Kiem tra xem co du lieu nganh_nghe_kinh_doanh ko, neu ko co nganh_nghe_kinh_doanh = nganh_nghe_kinh_doanh_2
					if($v_value==''&&$v_column_name=='nganh_nghe_kinh_doanh'&&($v_report_xml_file == '../xml/report/001_danh_sach_cac_ho_dang_ky_kinh_doanh_trong_thang_nam.xml'))
						$v_value = $arr_all_record[$row_index]['nganh_nghe_kinh_doanh_2'];
					//DatCQ: End
					//echo 'tt'.$v_value;
				}
				if ($v_type=="money"){
					$v_value = str_replace(",","",$v_value);
				}
				//In tu dong cua bao cao
				$v_html_body_row = $v_html_body_row . Report_Element_Type($v_type); 
				//Neu ma tinh so luong
				if ($v_calculate=="count"){
					if ((trim($v_compare_value)!="")&&(_list_have_element(trim($v_compare_value), trim($v_value),","))){
						$arr_calculate[$v_col_index] = $arr_calculate[$v_col_index] + 1;
						$arr_total_calculate[$v_col_index] = $arr_total_calculate[$v_col_index] + 1;
					}
				}elseif ($v_calculate=="sum"){//Neu tinh tong cac gia tri
					$v_value = str_replace(",","",$v_value);
					$arr_calculate[$v_col_index] = $arr_calculate[$v_col_index] + floatval($v_value);
					$arr_total_calculate[$v_col_index] = $arr_total_calculate[$v_col_index] + floatval($v_value);
				}else{						
					$arr_calculate[$v_col_index] = "";
					$arr_total_calculate[$v_col_index] = "";
				}
				$v_col_index ++;
				$table_struct_rec = $table_struct_rax->readRecord();
			}//End while
			$v_html_body = $v_html_body  .'<tr class="'.$v_current_style_name.'" >';
			$v_html_body = $v_html_body  .$v_html_body_row;
			$v_html_body = $v_html_body  .'</tr>';
			$v_inc ++;
			if (trim($v_group_by)!=""){	
				$v_current_row = $arr_all_record[$row_index+1];
				if ((sort_string_asc($v_old_row,$v_current_row)!=0)){
					//Khoi tao lai thu tu cua danh sach		
					$v_inc = 1;
					$group_index++;
					$v_html_temp = "";
					//Hien thi phan tinh toan theo nhom
					if ($v_calculate_group == "true"){
						for ($i=0,$n=sizeof($arr_calculate);$i < $n;$i++){
							if ($arr_calculate[$i]>=0){
								$v_type = $arr_type[$i];
								$v_align = $arr_align[$i];
								$v_value = $arr_calculate[$i];
								$arr_calculate[$i] = 0;
								if(in_array($v_report_xml_file,$arr_xml_file_general_report))
								{		
									if($i>=3)
										$v_html_temp = $v_html_temp .'<td class="data" align="'.$v_align.'"><B>'.$v_value.'&nbsp;</B></td>';						
								}
								else
								{
								
									if ($v_type=="money"){
										$v_html_temp = $v_html_temp .'<td class="data" align="'.$v_align.'">'.onegate_data_format($v_value).'&nbsp;</td>';
									}elseif($v_type=="identity"){
										$v_html_temp = $v_html_temp .'<td class="data" align="'.$v_align.'">&nbsp;</td>';
									}elseif($i==1){
										$v_html_temp = $v_html_temp .'<td class="data" align="'.$v_align.'"><B>C&#7897;ng:&nbsp;'.$v_group_name_label.'</B></td>';
									}else{
										$v_html_temp = $v_html_temp .'<td class="data" align="'.$v_align.'">'.$v_value.'&nbsp;</td>';
									}
								}
							}
						}
					}
					if(in_array($v_report_xml_file,$arr_xml_file_general_report))
					{
						$v_html_body =$v_html_group.$v_html_temp.$v_html_body;
						$v_html_body = $v_html_body  .'</tr>';
						$v_html_group = '';
						//In tieu de cua nhom
						if (trim($v_group_by)!="" && $row_index<$v_count-1){						
							$v_html_group = $v_html_body  .'<tr class="'.$v_current_style_name.'" >';
							$v_html_group = $v_html_group  .'<td class="data"><B>'.$group_index.'</B></td>';
							$v_html_group = $v_html_group  .'<td class="data" colspan = 2 ><B>'.$arr_all_record[$row_index + 1][$v_group_by].'</B></td>';
							$v_html_body = '';						
						}
					}
					else
					{
								
						$v_html_body = $v_html_body  .'<tr class="'.$v_current_style_name.'" >';
						$v_html_body = $v_html_body  .$v_html_temp;
						$v_html_body = $v_html_body  .'</tr>';
						//In tieu de cua nhom
						if (trim($v_group_by)!="" && $row_index<$v_count-1){
						//var_dump ($group_index);
							$v_html_body = $v_html_body  .'<tr class="'.$v_current_style_name.'" >';
							$v_html_body = $v_html_body  .'<td class="data"><B>'.$group_index.'</B></td>';
							
							if(in_array($v_report_xml_file,$array_tong_von_kinh_doanh)){
								if($arr_all_record[$row_index+1][$v_group_by]=="DKTD")
								{$v_name='&#272;&#259;ng k&yacute; thay &#273;&#7893;i';
								$v_html_body = $v_html_body  .'<td class="data" colspan="'.($v_column-1).'"><B>'.$v_name.' : '.$DKTD.'</B></td>';}
								if($arr_all_record[$row_index+1][$v_group_by]=="NKD"){
									$v_name='Ng&#7915;ng kinh doanh';
									$v_html_body = $v_html_body  .'<td class="data" colspan="'.($v_column-1).'"><B>'.$v_name.' : '.$NKD.'</B></td>';}							
							}
							else{
								$v_html_body = $v_html_body  .'<td class="data" colspan="'.($v_column-1).'"><B>'.$arr_all_record[$row_index+1][$v_group_by].'</B></td>';
							}					
							$v_html_body = $v_html_body  .'</tr>';
						}
					}
							
				}//End if							
				$v_old_row = $v_current_row;
			}							

			//Ket thuc mot dong
		}//End for
	}//End if
	//Hien thi phan tinh toan tong
	if ($v_calculate_total=="true"){
		$v_html_temp = "";
		for ($i=0;$i < $v_col_index;$i++){
			if ($arr_total_calculate[$i]>=0){
				$v_type = $arr_type[$i];
				$v_align = $arr_align[$i];
				$v_value = $arr_total_calculate[$i];
				if ($v_type=="money"){
					$v_html_temp = $v_html_temp .'<td class="data" align="'.$v_align.'">'.onegate_data_format($v_value).'&nbsp;</td>';
				}elseif($v_type=="identity"){
					$v_html_temp = $v_html_temp .'<td class="data" align="'.$v_align.'">&nbsp;</td>';
				}elseif($i==1){
					$v_html_temp = $v_html_temp .'<td class="data" align="'.$v_align.'"><B>T&#7893;ng c&#7897;ng&nbsp;</B></td>';			
				}else{
					$v_html_temp = $v_html_temp .'<td class="data" align="'.$v_align.'">'.$v_value.'&nbsp;</td>';
				}
			}
		}
		$v_html_body = $v_html_body  .'<tr class="'.$v_current_style_name.'" >';
		$v_html_body = $v_html_body  .$v_html_temp;
		$v_html_body = $v_html_body  .'</tr>';
	}
	if ($v_current_style_name == "odd_row"){
		$v_next_style_name = "round_row";
	}else{
		$v_next_style_name = "odd_row";
	}
//Ket thuc ban bang cua bao cao
	$v_html_body = $v_html_body  .'</table>';
	//Het phan than cua bao cao
	//*/
	//Lay cac thong tin ve tieu de cua bao cao
	$v_html_header = '';
	$table_struct_rax = new RAX(); 
	$table_struct_rec = new RAX(); 
	$table_struct_rax->open($v_report_xml_string);
	$table_struct_rax->record_delim = 'report_header';
	$table_struct_rax->parse();
	$table_struct_rec = $table_struct_rax->readRecord(); 
	$table_struct_row = $table_struct_rec->getRow();
	$v_report_unit = $table_struct_row["report_unit"];
	//$v_report_date = $table_struct_row["report_date"];
	$v_large_title = $table_struct_row["large_title"];
	
	//DatCQ: Bo sung (thang ... nam) 001 Danh Sach Cac Ho Dang Ky Kinh Doanh Trong Thang ... Nam
	$array_bcao_kdoanh_thang_nam = array('../xml/report/001_danh_sach_cac_ho_dang_ky_kinh_doanh_trong_thang_nam.xml',
										'../xml/report/001_danh_sach_cac_ho_cap_moi_dang_ky_kinh_doanh_trong_thang_nam.xml',
										'../xml/report/048_danh_sach_cac_ho_thay_doi_dang_ky_kinh_doanh_trong_thang_nam.xml',			
										'../xml/report/048_danh_sach_cac_ho_cap_lai_dang_ky_kinh_doanh_trong_thang_nam.xml',
										'../xml/report/048_danh_sach_cac_ho_cham_dut_kinh_doanh_trong_thang_nam.xml');
	if(in_array($v_report_xml_file,$array_bcao_kdoanh_thang_nam)){
		$table_struct_rax = new RAX(); 
		$table_struct_rec = new RAX(); 
		$table_struct_rax->open($v_xml_str);
		$table_struct_rax->record_delim = 'data_list';
		$table_struct_rax->parse();
		$table_struct_rec = $table_struct_rax->readRecord(); 
		$table_struct_row = $table_struct_rec->getRow();
		$v_large_title = str_replace('#thang#',_restore_XML_bad_char($table_struct_row["thang_bao_cao"]),$v_large_title);
		$v_large_title = str_replace('#nam#',_restore_XML_bad_char($table_struct_row["nam_bao_cao"]),$v_large_title);
		//echo $v_large_title;
	}
	//DatCQ: End
	$v_small_title = $table_struct_row["small_title"];
	$v_html_header = $v_html_header  .'<table width="99%" border="0" cellpadding="0" cellspacing="0">';
	//$v_html_header = $v_html_header  .'<col width:"20%"><col width:"20%"><col width:"20%"><col width:"20%"><col width:"20%">';
	$v_html_header = $v_html_header  . $v_html_col_list;
	if(!$v_move_record_to_leader_cheched){
		$v_html_header = $v_html_header  .'<tr valign="top"><td align="center" class="report_unit_name" colspan="'.floor($v_column/2).'">'.$_ISA_OWNER_NAME."<br>" .$v_report_unit.'<br>----------------------'.'<br> Số:......</td>';
		$v_html_header = $v_html_header  .'<td align="center" class="freedom_republic" colspan="'.($v_column-floor($v_column/2)).'">'.CONST_REPORT_REPUBLIC_TITLE."<br>".CONST_REPORT_FREEDOM_TITLE.'<br> ------------------------</td>';
		$v_html_header = $v_html_header  .'</tr><tr><td align="center" class="normal_label" colspan="'.$v_column.'">&nbsp;</td>';
		$v_html_header = $v_html_header  .'</tr><tr><td align="center" class="normal_label" colspan="'.$v_column.'"><br></td>';
		$v_html_header = $v_html_header  .'</tr><tr><td align="right" class="date" colspan="'.$v_column.'"><i>'.$v_report_date.', '.$v_current_date.'</i></td>';
	}
	$v_html_header = $v_html_header  .'</tr><tr><td align="center" class="normal_label" colspan="'.$v_column.'">&nbsp;</td>';
	$v_html_header = $v_html_header  .'</tr><tr><td align="center" class="title" colspan="'.$v_column.'">'.$v_large_title.'</td>';
	$v_html_header = $v_html_header  .'</tr><tr><td align="center" class="sub_title" colspan="'.$v_column.'">'.$v_small_title.'</td>';
	$v_html_header = $v_html_header  .'</tr><tr><td align="center" class="normal_label" colspan="'.$v_column.'">&nbsp;</td>';
	$v_html_header = $v_html_header  .'</tr><tr><td align="center" class="normal_label" colspan="'.$v_column.'">&nbsp;</td>';
	$v_html_header = $v_html_header  .'</tr></table>';
	//Het phan tieu de cua bao cao
}

//========================================else: Bao cao tien do cua vpdkqsdd===========================================
else {
	$v_report_xml_string = _read_file($v_report_xml_file);
	//echo htmlspecialchars($v_report_xml_string); exit;
	//lay du lieu cua bao cao
	$table_struct_rax = new RAX(); 
	$table_struct_rec = new RAX(); 
	$table_struct_rax->open($v_report_xml_string);
	$table_struct_rax->record_delim = 'report_sql';
	$table_struct_rax->parse();
	$table_struct_rec = $table_struct_rax->readRecord(); 
	$table_struct_row = $table_struct_rec->getRow();
	
	//Lay danh sach tien do cac ho so co trong bao cao 
	$v_sql_string = _restore_XML_bad_char($table_struct_row["sql"]);
	$v_sql_string = replace_tag_xml_value_in_sql($v_sql_string,$v_report_xml_string,$v_xml_str);
	
	//Lay danh sach ho so co trong bao cao
	$v_sql_string_2 = _restore_XML_bad_char($table_struct_row["sql_1"]);
	$v_sql_string_2 = replace_tag_xml_value_in_sql($v_sql_string_2,$v_report_xml_string,$v_xml_str);
//	echo $v_sql_string_2;
	
	//Lay du lieu cua bao cao tu database
	$arr_all_record = Query_Data_For_Colunm_name($v_sql_string);
	//var_dump($arr_all_record[1]); exit;

	//Lay danh sach ho so co trong bao cao vao mang
	$arr_all_record_2 = Query_Data_For_Colunm_name($v_sql_string_2);
	//var_dump($arr_all_record_2); exit;
	
	//Nhom du lieu theo mot the bat ky trong chuoi XML
	//usort($arr_all_record,'sort_string_asc');
	$v_count = sizeof($arr_all_record);
	$v_count_2 = sizeof($arr_all_record_2);

	//lay cac thong tin tieu de cua form
	
	$table_struct_rax = new RAX(); 
	$table_struct_rec = new RAX(); 
	$table_struct_rax->open($v_report_xml_string);
	$table_struct_rax->record_delim = 'table_struct_of_filter_form';
	$table_struct_rax->parse();
	$table_struct_rec = $table_struct_rax->readRecord(); 
	$table_struct_row = $table_struct_rec->getRow();
	$v_form_title = $table_struct_row["form_title"];
	
	//Xau chua toan bo bao cao
	$v_html_string = '';
	//Phan than cua bao cao	//cac tieu de cot
	$v_html_body = '';
	$v_html_temp_width = '';
	$v_html_temp_label = '';
	
	//Lay cac thong tin ve tieu de cua bao cao
	$v_html_header = '';
	$table_struct_rax = new RAX(); 
	$table_struct_rec = new RAX(); 
	$table_struct_rax->open($v_report_xml_string);
	$table_struct_rax->record_delim = 'report_header';
	$table_struct_rax->parse();
	$table_struct_rec = $table_struct_rax->readRecord(); 
	$table_struct_row = $table_struct_rec->getRow();
	$v_report_unit = $table_struct_row["report_unit"];
	$v_large_title = $table_struct_row["large_title"];
	$v_small_title = $table_struct_row["small_title"];
	$v_html_header = $v_html_header  .'<table width="100%" border="0" cellpadding="0" cellspacing="0">';
	if(!$v_move_record_to_leader_cheched){
		$v_html_header = $v_html_header  .'<tr valign="top"><td align="center" style="padding-right:2.5in" class="report_unit_name">'.$_ISA_OWNER_NAME."<br>" .$v_report_unit.'<br>----------------------'.'<br> Số:......</td>';
		$v_html_header = $v_html_header  .'<td align="center" class="freedom_republic">'.CONST_REPORT_REPUBLIC_TITLE."<br>".CONST_REPORT_FREEDOM_TITLE.'<br> ------------------------</td>';
		$v_html_header = $v_html_header  .'</tr><tr><td align="center" class="normal_label" >&nbsp;</td>';
		$v_html_header = $v_html_header  .'</tr><tr><td align="center" class="normal_label" ><br></td>';
		$v_html_header = $v_html_header  .'</tr><tr><td align="right" style="padding-right:0.5in" colspan="2" class="date" ><i>'.$v_report_date.', '.$v_current_date.'</i></td>';
	}
		$v_html_header = $v_html_header  .'</tr><tr><td align="center" class="normal_label" >&nbsp;</td>';
		$v_html_header = $v_html_header  .'</tr><tr><td align="center" colspan="2" class="title" >'.$v_large_title.'</td>';
		$v_html_header = $v_html_header  .'</tr><tr><td align="center" colspan="2" class="sub_title" >'.$v_small_title.'</td>';
		$v_html_header = $v_html_header  .'</tr><tr><td align="center" class="normal_label" >&nbsp;</td>';
		$v_html_header = $v_html_header  .'</tr><tr><td align="center" class="normal_label" >&nbsp;</td>';
		$v_html_header = $v_html_header  .'</tr></table>';
	//Het phan tieu de cua bao cao
	
	//==========Phan than cua bao cao=====================================================================
	for($ii=0;$ii<$v_count_2;$ii++){

		$v_html_body = $v_html_body.'<hr width="100%" color="#0000FF"/><table border="0" cellpadding="0" cellspacing="0">';
		$v_html_body = $v_html_body.'<tr width="100%" class="sub_title">'.$arr_all_record_2[$ii]["C_CODE"].' :'.$arr_all_record_2[$ii]["REGISTOR_NAME"].'</tr>';
		$v_html_body = $v_html_body.'<tr>';
	
		$v_html_body = $v_html_body.'<td><table style="width:99%" border="0" cellpadding="0" cellspacing="0">';
		
		//Ten loai cong viec
		$v_html_body = $v_html_body.'<tr>';	
		for($a=0;$a<$v_count;$a++){	
			if($arr_all_record[$a]["C_CODE"]==$arr_all_record_2[$ii]["C_CODE"]){
				$v_html_body = $v_html_body.'<td class="data" align="center"  >'.$arr_all_record[$a]["C_NAME"].' ('.$arr_all_record[$a]["C_NUMBER"].')'.'</td>';
			}
		}
		$v_html_body = $v_html_body.'</tr>';
			
		//Ngay thuc hien loai cong viec do
		$v_html_body = $v_html_body.'<tr>';
		
		for($a=0;$a<$v_count;$a++){	
			if($arr_all_record[$a]["C_CODE"]==$arr_all_record_2[$ii]["C_CODE"]){
				$v_color = '';
				if($arr_all_record[$a]["C_CODE"]==$arr_all_record[$a-1]["C_CODE"]&&$a>0){
					$songay = intval(dateDiff($arr_all_record[$a-1]["C_DATE"], $arr_all_record[$a]["C_DATE"]));
					if($songay > intval($arr_all_record[$a]["C_NUMBER"])){
						$v_color = "#FF0000";
					}
				}
				$v_html_body = $v_html_body.'<td class="data" align="center" style="background-color:'.$v_color.'"><div style="width:95%">'.Get_DMY($arr_all_record[$a]["C_DATE"]).'</div></td>';
			}
		}
		$v_html_body = $v_html_body.'<tr>';		
		$v_html_body = $v_html_body.'</table></td>';		
		$v_html_body = $v_html_body.'</tr>';
		$v_html_body = $v_html_body.'</table>';
	}
	//===================================Het phan than cua bao cao=======================================
} // Het vong else

/******************** bao cao 011 - 012 - 013******************************************** */
/******************** modified by tuyenntt ************************************************/
$v_array_report_xml_file_giao_nhan =  array( "../xml/report/011_bao_cao_giao_nhan.xml",
											"../xml/report/012_bao_cao_nhat_ky_giao_nhan_hso.xml",
											"../xml/report/013_bao_cao_nhat_ky_giao_nhan_.xml"				
											);
if(in_array($v_report_xml_file,$v_array_report_xml_file_giao_nhan)==true)
{
$v_html_temp="<table width='100%'  border='0' cellspacing='0' cellpadding='0'>
<tr>
	<td style='font-size:15px; font-weight: normal;	vertical-align:middle;font-family:arial;' colspan='4'>&#272;&#7841;i di&#7879;n ph&ograve;ng Qu&#7843;n l&yacute; &#273;&ocirc; th&#7883; nh&#7853;n:&nbsp;&nbsp;&nbsp".sizeof($arr_all_record)." h&#7891; s&#417;
	</td>
</tr>";
$v_html_temp=$v_html_temp.
"<tr>
	<td style='font-size:15px; font-weight: normal;	vertical-align:middle ;font-family:arial;' colspan='4' >(T&#7915; s&#7889;:". "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$arr_all_record[0]['ma_ho_so']. "&nbsp;&nbsp;&nbsp;"."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#272;&#7871;n s&#7889;:". "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$arr_all_record[sizeof($arr_all_record) - 1]['ma_ho_so'].")
	</td>
</tr>";
$v_html_temp= $v_html_temp.
"<tr>
	<td style='font-size:15px; font-weight: normal;	vertical-align:middle;font-family:arial;' colspan='4'>H&#7891; s&#417; nh&#7853;n l&#7841;i:&nbsp;............................................................................... h&#7891; s&#417;
	</td>
</tr>
<tr> 
	<td style='font-size:15px; font-weight: normal;	vertical-align:middle;font-family:arial; ' colspan='4'> (G&#7891;m.....................................................................................................................................................
   </td>
</tr>
<tr>
	<td style='font-size:15px; font-weight: normal;	vertical-align:middle;font-family:arial;font-family:arial;' colspan='4'>	...............................................................................................................................................................
	</td>
</tr>
<tr>
	<td style='font-size:15px; font-weight: normal;	vertical-align:middle;font-family:arial;' colspan='4'> ...............................................................................................................................................................)
	</td>
</tr>";
$v_html_body =$v_html_temp.$v_html_body;
}
/********************/
//Phan chua cac tieu thuc loc bao cao
$table_struct_rax = new RAX(); 
$table_struct_rec = new RAX(); 
$table_struct_rax->open($v_report_xml_string);
$table_struct_rax->record_delim = 'row';
$table_struct_rax->parse();
$table_struct_rec = $table_struct_rax->readRecord(); 
while ($table_struct_rec) { 
	$table_struct_row = $table_struct_rec->getRow();
	$v_tag_list = $table_struct_row["tag_list"];
	$v_row_id = $table_struct_row["row_id"];
	$arr_tag = explode(",", $v_tag_list);
	//Bang chua mot dong cua form
	$v_html_header = $v_html_header . "<table width='99%'  border='0' cellspacing='0' cellpadding='0'>";
	$v_html_table = "";
	$v_html_tag = "";									
	for($i=0;$i < sizeof($arr_tag);$i++){
		$formfield_rax = new RAX(); 
		$formfield_rec = new RAX(); 
		$formfield_rax->open($v_report_xml_string);
		$formfield_rax->record_delim = $arr_tag[$i];
		$formfield_rax->parse();
		$formfield_rec = $formfield_rax->readRecord(); 
		$formfield_row = $formfield_rec->getRow(); 
		$v_label = $formfield_row["label"];
		$v_type = $formfield_row["type"];
		$v_dataformat = $formfield_row["data_format"];
		$v_width = $formfield_row["width"];
		$v_row = $formfield_row["row"];
		$v_max = $formfield_row["max"];
		$v_min = $formfield_row["min"];
		$v_maxlength = $formfield_row["maxlength"];
		$v_note = $formfield_row["note"];
		$v_message = $formfield_row["message"];
		$v_optional = $formfield_row["optional"];
		$v_xml_tag_in_db = $formfield_row["xml_tag_in_db"];
		$v_js_function_list = $formfield_row["js_function_list"];
		$v_js_action_list = $formfield_row["js_action_list"];
		$v_readonly_in_edit_mode = $formfield_row["readonly_in_edit_mode"];
		$v_disabled_in_edit_mode = $formfield_row["disabled_in_edit_mode"];
		if ($v_xml_str!=""){
			$column_rax = new RAX(); 
			$column_rec = new RAX();
			$column_rax->open($v_xml_str);
			$column_rax->record_delim = 'data_list';
			$column_rax->parse();
			$column_rec = $column_rax->readRecord(); 
			$column_row = $column_rec->getRow();
			$v_value = _restore_XML_bad_char($column_row[$v_xml_tag_in_db]); 
		}
		
		$array_mat_tieu_de = array('../xml/report/001_danh_sach_cac_ho_dang_ky_kinh_doanh_trong_thang_nam.xml',
									'../xml/report/001_danh_sach_cac_ho_cap_moi_dang_ky_kinh_doanh_trong_thang_nam.xml',
									'../xml/report/048_danh_sach_cac_ho_thay_doi_dang_ky_kinh_doanh_trong_thang_nam.xml',
									'../xml/report/048_danh_sach_cac_ho_cap_lai_dang_ky_kinh_doanh_trong_thang_nam.xml',
									'../xml/report/048_danh_sach_cac_ho_cham_dut_kinh_doanh_trong_thang_nam.xml');
									
		//DatCQ: Lam mat tieu de cua nhung tieu thuc loc ko co gia tri 260908
		if	($v_value == ""&&in_array($v_report_xml_file,$array_mat_tieu_de)==1){
			break;
		}
		//End : Lam mat tieu de cua nhung tieu thuc loc ko co gia tri 260908
		
		if ($v_type=="selectbox"){
			$v_selectbox_option_sql = $formfield_row["selectbox_option_sql"];
			$v_selectbox_id_column = $formfield_row["selectbox_option_id_column"];
			$v_selectbox_name_column = $formfield_row["selectbox_option_name_column"];
		}
		if ($v_type=="checkboxmultiple"){
			$v_checkbox_multiple_sql = $formfield_row["checkbox_multiple_sql"];
			$v_checkbox_multiple_id_column = $formfield_row["checkbox_multiple_id_column"];
			$v_checkbox_multiple_name_column = $formfield_row["checkbox_multiple_name_column"];
		}
		$v_html_table = $v_html_table . "<col width='$v_first_col_width'>" . "<col width='$v_second_col_width'>";		
		$v_html_tag = $v_html_tag . Generate_HTML_Output();		
	}
	$v_html_header = $v_html_header .  $v_html_table . "<tr><td class='normal_label' align='center' colspan='$v_column'>" . $v_html_tag."</td></tr>";
	$v_html_header = $v_html_header . "</table>";
	$table_struct_rec = $table_struct_rax->readRecord();
}
$v_html_header = $v_html_header . "<table width='99%'  border='0' cellspacing='0' cellpadding='0'>";
$v_html_header = $v_html_header . "<tr><td colspan='$v_column'>&nbsp;</td></tr>";
$v_html_header = $v_html_header . "</table>";
//Het phan bang chua cac tieu thuc loc

//lay cac thong tin phan cuoi cua bao cao
$v_html_footer = '';
$table_struct_rax = new RAX(); 
$table_struct_rec = new RAX(); 
$table_struct_rax->open($v_report_xml_string);
$table_struct_rax->record_delim = 'report_footer';
$table_struct_rax->parse();
$table_struct_rec = $table_struct_rax->readRecord(); 
$table_struct_row = $table_struct_rec->getRow();
$v_report_creator = $table_struct_row["report_creator"];
$v_report_approver = $table_struct_row["report_approver"];
$v_report_signer = $table_struct_row["report_signer"];
$v_html_footer = $v_html_footer  .'<table width="99%" border="0" cellspacing="0" cellpadding="0">';
$v_html_footer = $v_html_footer  . $v_html_col_list;
$v_html_footer = $v_html_footer  .'<tr><td class="normal_label" colspan="'.$v_column.'">&nbsp;</td></tr><tr>';
$v_html_footer = $v_html_footer  .'<tr><td class="normal_label" colspan="'.$v_column.'">&nbsp;</td></tr><tr>';
$v_html_footer = $v_html_footer  .'<td class="normal_label">&nbsp;</td>';
$v_html_footer = $v_html_footer  .'<td align="center" class="creator">'.$v_report_creator.'&nbsp;</td>';
$v_html_footer = $v_html_footer  .'<td align="center" class="approver">'.$v_report_approver.'&nbsp;</td>';
$v_html_footer = $v_html_footer  .'<td align="center" class="signer">'.$v_report_signer.'&nbsp;</td>';
$v_html_footer = $v_html_footer  .'</tr></table>';
/**************************them footer cua bao cao 001,002,048 **********************/

/*************************the end the modified by tuyenntt ***************************************/
$array_hien_tong = array('../xml/report/001_danh_sach_bao_cao_thay_doi.xml',
						'../xml/report/001_danh_sach_ho_so_ngung_kinh_doanh.xml',
						'../xml/report/001_danh_sach_cac_ho_dang_ky_kinh_doanh_trong_thang_nam.xml',
						'../xml/report/001_danh_sach_cac_ho_cap_moi_dang_ky_kinh_doanh_trong_thang_nam.xml',
						'../xml/report/048_danh_sach_bao_cao_thay_doi_ndkd.xml',
						'../xml/report/048_danh_sach_cac_ho_thay_doi_dang_ky_kinh_doanh_trong_thang_nam.xml',
						'../xml/report/048_danh_sach_cac_ho_cap_lai_dang_ky_kinh_doanh_trong_thang_nam.xml',
						'../xml/report/048_danh_sach_cac_ho_cham_dut_kinh_doanh_trong_thang_nam.xml');
if(in_array($v_report_xml_file,$array_hien_tong)){
$v_html_footer="<tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td>T&#7893;ng s&#7889; v&#7889;n kinh doanh: </td></tr>".convertMoney($tong)."</td></tr>".$v_html_footer;

$v_html_footer="<table><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td>T&#7893;ng s&#7889; h&#7897; kinh doanh: ".sizeof($arr_all_record)."</td></tr></table>".$v_html_footer;
}

//DatCQ Tinh tong cac cot dien tich xay dung, dien tich san bao cao 009_danh_sach_cap_phep_xay_dung_theo_hinh_thuc_ghi_chu.xml
if($v_report_xml_file=='../xml/report/009_danh_sach_cap_phep_xay_dung_theo_hinh_thuc_ghi_chu.xml')
{
$v_html_footer="<table><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td>T&#7893;ng di&#7879;n t&iacute;ch x&acirc;y d&#7921;ng: ".$tong_dtxd."</td></tr></table>".$v_html_footer;
$v_html_footer="<table><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td>T&#7893;ng di&#7879;n t&iacute;ch s&agrave;n: ".$tong_dts."</td></tr></table>".$v_html_footer;
}


//ket hop cac phan cua bao cao
$v_html_string = $v_html_string.$v_html_header.$v_html_body.$v_html_footer;
//$v_html_string = $v_html_string.$v_html_header.$v_html_body;

str_replace('report_table','list_table_print',$v_html_string);
//echo $v_html_string; 

//Xuat ra file theo dinh dang html
$v_style_file = "report_style.css";
$v_str_style = _read_file($v_style_file);
//Phan dau cua chuoi html
$v_html_content = '<html xmlns:o="urn:schemas-microsoft-com:office:office"
					xmlns:x="urn:schemas-microsoft-com:office:excel">
					<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
$v_html_content = $v_html_content.'<style type=text/css><!--'.$v_str_style.'--></style>';
//Phan dinh dang cac bang cua Exel
$v_html_content = $v_html_content.'<!--[if gte mso 9]><xml>
									 <x:ExcelWorkbook>
									  <x:ExcelWorksheets>
									   <x:ExcelWorksheet>
										<x:Name>Report</x:Name>
										<x:WorksheetOptions>
										 <x:Print>
										  <x:ValidPrinterInfo/>
										  <x:HorizontalResolution>600</x:HorizontalResolution>
										  <x:VerticalResolution>600</x:VerticalResolution>
										 </x:Print>
										 <x:PageBreakZoom>100</x:PageBreakZoom>
										 <x:Selected/>
										 <x:Panes>
										  <x:Pane>
										   <x:Number>0</x:Number>
										   <x:ActiveRow>0</x:ActiveRow>
										   <x:ActiveCol>0</x:ActiveCol>
										  </x:Pane>
										 </x:Panes>
										 <x:ProtectContents>False</x:ProtectContents>
										 <x:ProtectObjects>False</x:ProtectObjects>
										 <x:ProtectScenarios>False</x:ProtectScenarios>
										</x:WorksheetOptions>
										<x:Sorting>
										 <x:Sort>ma</x:Sort>
										</x:Sorting>
									   </x:ExcelWorksheet>
									  </x:ExcelWorksheets>
									  <x:WindowHeight>9345</x:WindowHeight>
									  <x:WindowWidth>15180</x:WindowWidth>
									  <x:WindowTopX>120</x:WindowTopX>
									  <x:WindowTopY>60</x:WindowTopY>
									  <x:ProtectStructure>False</x:ProtectStructure>
									  <x:ProtectWindows>False</x:ProtectWindows>
									 </x:ExcelWorkbook>
									</xml><![endif]-->';
$v_html_content = $v_html_content.'</head><body>'.$v_html_string.'</body>';
$v_html_content = $v_html_content.'</html>';
switch($v_export_type) {
	case 1;
		$v_export_filename = "report.htm";
		break;
	case 2;
		$v_html_content = str_replace('text/html','application/msword',$v_html_content);		
		$v_export_filename = "report.doc";
		break;
	case 3;
		$v_export_filename = "report.xls";
		$v_html_content = str_replace('text/html','application/vnd.ms-excel',$v_html_content);		
		break;
	default:
		$v_export_filename = "report.htm";
		break;	
}
if($v_export_filename == "report.htm") 
	echo $v_html_content;
else{
	_write_file($v_export_filename ,$v_html_content);
	$htmlString  = "<form action='index.php' method='post' name='f_dsp_single_conditions'>";
	$htmlString .= "<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
	$htmlString .= "<tr><td height='20pt'></td></tr>";
	$htmlString .= "<tr align='center'>";
	$htmlString .= " <td colspan='5'>";
	$htmlString .= " <input type='hidden' name='fuseaction' value='DISPLAY_SINGLE_CONDITIONS'>";
	/* <!--
	<input type='button' class='normal_button' name='btn_back' value='<?php echo _CONST_BACK_BUTTON;?>' onClick='btn_back_onclick(\'DISPLAY_SINGLE_CONDITIONS\')' onKeyDown='change_focus(documen.forms(0),this)'>
	-->*/
	$htmlString .= " </td> ";
	$htmlString .= " </tr>";
	$htmlString .= "</table>";
	$htmlString .= "</form>";
	$htmlString .= "<script language='JavaScript'>";
	/* //document.forms(0).submit();*/
	$htmlString .= " goto_url('".$v_export_filename."',1);";
	$htmlString .= "</script>";
	echo $htmlString; 
?>
<form action='index.php' method='post' name='f_dsp_single_conditions'>
<table width='100%' border='0' cellspacing='0' cellpadding='0'>
	<tr><td height="20pt"></td></tr>
	<tr align="center">
		<td colspan="5">
			<input type='hidden' name='fuseaction' value='DISPLAY_SINGLE_CONDITIONS'>
			<!--
			<input type='button' class='normal_button' name="btn_back" value='<?php echo _CONST_BACK_BUTTON;?>' onClick="btn_back_onclick('DISPLAY_SINGLE_CONDITIONS')" onKeyDown="change_focus(document.forms(0),this)">
			-->
		</td>	
	</tr>
</table>
</form>
<script language="JavaScript">
	//document.forms(0).submit();
	goto_url("<?php echo $v_export_filename ?>",1);
</script>
<?php }?>